﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ZCrawler;

namespace ZCrawlerManager
{
    public partial class FrmTemplate : DevExpress.XtraEditors.XtraForm
    {
        public ZTemplate template;
        public DialogResult result;
        public FrmTemplate()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            template = new ZTemplate();
            template.fields = lstFields.Items.OfType<string>().ToList();
            template.title = txtTitle.Text;
            result = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            result = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if(!lstFields.Items.Contains(txtFieldName.Text))
                    lstFields.Items.Add(txtFieldName.Text);
            }
            catch (Exception) { }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                lstFields.Items.RemoveAt(lstFields.SelectedIndex);
            }
            catch (Exception) { }
        }
    }
}